﻿using System;
using System.Collections.Generic;

namespace Moonlite.Data.EditorInterop.Internal
{
    public static class FloatArrayUtils
    {
        public static float[] ConvertStringToFloatArray(string floats)
        {
            List<float> listOfFloats = new List<float>();
            foreach (string @float in floats.Split(','))
            {
                float actualFloat = 0f;
                if (float.TryParse(@float.Trim(), out actualFloat))
                {
                    listOfFloats.Add(actualFloat);
                }
            }

            return listOfFloats.ToArray();
        }

        public static string ConvertFloatArrayToString(float[] floats)
        {
            string actualString = "";
            int index = 0;
            foreach (float @float in floats)
            {
                actualString += @float.ToString();
                if (index < floats.Length - 1)
                {
                    actualString += ", ";
                }

                index++;
            }

            return actualString;
        }
    }
}
